package com.intelligentcar.springboot.service.serverImpl;

import com.intelligentcar.springboot.bean.*;
import com.intelligentcar.springboot.mapper.StaffMapper;
import com.intelligentcar.springboot.service.StaffServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Random;

@Service
public class StaffServerImpl implements StaffServer {
    @Autowired
    private StaffMapper staffMapper;

    @Override
    public int addStaffData() {
        Random rm = new Random();
//        String time =new SimpleDateFormat("yyyy-MM-dd-HH:mm:ss").format(new Date());
        String time1 =new SimpleDateFormat("yyyy-MM-dd").format(new Date());
//        String time2=new SimpleDateFormat("HH:mm:ss").format(new Date());
        List<Manager> list = staffMapper.selectAllStaff();
        List<StaffAttendance> list2 = staffMapper.ifTodayData(time1);
        if (list2.size()>0) {
        }else{
            if (list.size()>0){
                for (int i = 0; i<list.size(); i++){
                    StaffAttendance staffAttendance = new StaffAttendance();
                    staffAttendance.setDate(time1);
                    staffAttendance.setInTime("09:00");
                    staffAttendance.setOutTime("17:00");
                    int k = rm.nextInt(list.size());
                    staffAttendance.setUid(list.get(k).getUId());
                    staffMapper.addStaffData(staffAttendance);
                    System.out.println("8888");
                }
            }
        }
        return 1;
    }
}
